package test;
import java.io.IOException;
import org.junit.Test;
import java.util.*;

import junit.framework.*;
import junit.textui.*;
import Phase1.*;
public class testCommunication extends TestCase
{
	
	private final int DEFAULT_SERVER_PORT = 3000;
	private final int DEFAULT_CLIENT_PORT = 3000;
	
	 
	@Test
	public void testEmptyCollection() 
	{
		Collection<?> collection = new ArrayList();
		assertTrue(collection.isEmpty());
		
	}
	@Test
	public void testServerRun()
	{
		Server server = new Server();
		
		assertTrue(server instanceof Server);
		assertTrue(server instanceof Thread);
	//	assertTrue(false);
		server.done();
	}
	@Test
	public void testStringMessage() throws Exception
	{
		Server server = new Server(DEFAULT_SERVER_PORT);
		
		String t = new String("here is the data");
		try 
		{ 
			assertTrue(t.equals(Client.sendData("localhost", DEFAULT_CLIENT_PORT, t))); 
		} catch (IOException e) 
		{
			//catching part should be skiped in coverage
			e.printStackTrace();
		} 
		catch (ClassNotFoundException e)
		{
			//catching part should be skiped in coverage
			e.printStackTrace();
		}
		server.done();
		 
	}
	@Test
	public void testNullMessage() throws Exception
	{
		Server server = new Server();
		
		String t = new String("here is the data");
		try 
		{ 
			assertTrue(t.equals(Client.sendData("localhost", DEFAULT_CLIENT_PORT , t)));
			assertTrue(false);
		}
		catch(AssertionError e)
		{
			assertTrue(true);
		}
		catch (IOException e) 
		{//catching part might be skipped in coverage
			e.printStackTrace();
		}//catching part might be skipped in coverage
		catch (ClassNotFoundException e) 
		{//catching part might be skipped in coverage
			e.printStackTrace();
		}
		server.done();
	}
	@Test
	public void testServerHalt() throws Exception
	{
		Server server = new Server();
		
		try 
		{
			Client.setLinkToServer("localhost", DEFAULT_CLIENT_PORT);
		} catch (IOException e) 
		{
			//catching part might be skipped in coverage
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) 
		{
			//catching part might be skipped in coverage
			e.printStackTrace();
		}
		
		server.done();
		
	}

}
